<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>车辆详情 -- 车辆报告 --质检报告 win</title>

</head>

<body>



</body>

<script type="text/javascript" >
    let string1='2[abc]';
    let string2='2[2[a]2[b]1[c]]';
    let string3='2[2[2[a]1[b]]]';

    let p=/\d\[[a-z]*\]/g
    let d=/\d/g
    function toRes(str){
        let arr=str.match(p)
        if(arr.length>0){
            for (let i=0;i<arr.length;i++){
                str=str.replace(arr[i],toString(arr[i]))
            }
        }
        let sss=str
        if(str.match(d)){
            sss=toRes(str)
        }
        return sss
    }
    function toString(str){
        let arr= str.split('[')
        arr[1]=arr[1].slice(0,arr[1].length-1)
        let s=''
        for(let i=0;i<arr[0];i++){
            s+=arr[1]
        }
        return s
    }
    console.log(toRes(string1))
</script>

</html>
